class Solution(object):
    def removeComments(self, source):
        """
        :type source: List[str]
        :rtype: List[str]
        """
        out = []
        state = 0
        n = len(source)
        index = 0
        s = source[index]
        last = ''
        while True:
            if state == 0:
                if '/*' in s:
                    s1 = s.split('/*', 1)
                    if '//' in s:
                        s2 = s.split('//', 1)
                        if s1[0] < s2[0]:
                            last += s1[0]
                            if '*/' in s1[1]:
                                s3 = s1[1].split('*/', 1)
                                s = s3[1]
                            else:
                                state = 1
                                index += 1
                                if index < n:
                                    s = source[index]
                                else:
                                    break
                        else:
                            if last + s2[0]:
                                out.append(last + s2[0])
                            last = ''
                            index += 1
                            if index < n:
                                s = source[index]
                            else:
                                break
                    else:
                        last = s1[0]
                        if '*/' in s1[1]:
                            s3 = s1[1].split('*/', 1)
                            s = s3[1]
                        else:
                            state = 1
                            index += 1
                            if index < n:
                                s = source[index]
                            else:
                                break
                else:
                    if '//' in s:
                        s2 = s.split('//', 1)
                        if last + s2[0]:
                            out.append(last + s2[0])
                        last = ''
                        index += 1
                        if index < n:
                            s = source[index]
                        else:
                            break
                    else:
                        if last + s:
                            out.append(last + s)
                        last = ''
                        index += 1
                        if index < n:
                            s = source[index]
                        else:
                            break
            else:
                if '*/' in s:
                    s1 = s.split('*/', 1)
                    s = s1[1]
                    state = 0
                else:
                    index += 1
                    s = source[index]
        return out





data = Solution()
source = ["/*Test program */", "int main()", "{ ", "  // variable declaration ", "int a, b, c;", "/* This is a test", "   multiline  ", "   comment for ", "   testing */", "a = b + c;", "}"]
print(data.removeComments(source))
source = ["a/*comment", "line", "more_comment*/b"]
print(data.removeComments(source))
source = ["a/*comment*/ab/*12312*/12//12312", "line"]
print(data.removeComments(source))